package com.junyuan.fxf_pad.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.junyuan.fxf_pad.R;
import com.junyuan.fxf_pad.application.MyApplication;

import java.util.ArrayList;

public class PlayVoiceActivity extends AppCompatActivity {
    ListView lv;
    ArrayAdapter adapter;
    ArrayList<String> mVoiceList;
    Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_voice);

        lv = (ListView) findViewById(R.id.lvVoiceList);
        intent = getIntent();
        Bundle bundle = intent.getBundleExtra("Bundle");
        mVoiceList = bundle.getStringArrayList("VoiceList");
        adapter = new ArrayAdapter(this, R.layout.item_voice, mVoiceList);
        lv.setAdapter(adapter);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                Log.d("mytag", "点击了" + position + "位置");
                String data = String.valueOf(position + 1);
                if (MyApplication.instance.mBleService != null) {
                    MyApplication.instance.mBleService.writeCharacteristic(MyApplication.instance.mCharacteristic, data);
                }
                Intent intent = new Intent(PlayVoiceActivity.this, VoicePlayListActivity.class);
                startActivity(intent);

            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();


        if (MyApplication.instance.mBleService != null) {
            MyApplication.instance.mBleService.writeCharacteristic(MyApplication.instance.mCharacteristic, "#E");
        }
    }
}
